package persistance.database.dao;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;

import persistance.hibernate.InitSessionFactory;
import domain.valueObejcts.Floor;

public class FloorDAO {

	private static Session session;

	public static void create() {
		session = InitSessionFactory.getInstance().getCurrentSession();
		Transaction tx = session.beginTransaction();
		
		Floor floor1 = new Floor();
		floor1.setName("1. Stockwerk");
		session.save(floor1);
		
		Floor floor2 = new Floor();
		floor2.setName("2. Stockwerk");
		session.save(floor2);
		
		Floor floor3 = new Floor();
		floor3.setName("3. Stockwerk");
		session.save(floor3);
		
		Floor floor4 = new Floor();
		floor4.setName("4. Stockwerk");
		session.save(floor4);
		
		Floor floor5 = new Floor();
		floor5.setName("5. Stockwerk");
		session.save(floor5);
		
		tx.commit();
	}
	
	@SuppressWarnings("unchecked")
	public static List<Floor> read(int id) {
		List<Floor> result = new ArrayList<Floor>();
		
		session = InitSessionFactory.getInstance().getCurrentSession();
		Transaction tx = session.beginTransaction();
		Query query = session.createQuery("FROM Floor WHERE id = :id");
		query.setParameter("id", id);
		
		result = query.list();
		tx.commit();
		
		return result;
	}

}
